/*
 * 中北大学软件学院 刘俊 版权所有
 */
package com.zbdx.uolab.user.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.zbdx.uolab.util.DbUtil;

/**
 *
 * @author 刘俊
 * @version 1.0
 * @date 2021年1月26日 
 */
public class UserDaolmpl implements UserDao {
	@Override
	public boolean login(String userName, String userPsw) {
		Connection conn = null;
		ResultSet rs = null;
		PreparedStatement pstmt = null;
		boolean loginFlag = false;
		
		conn = DbUtil.getConnection();
		String sql = "SELECT * FROM t_user WHERE username=? AND password=?";
		try {
			pstmt = conn.prepareStatement(sql);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			pstmt.setString(1, userName);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			pstmt.setString(2, userPsw);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			rs = pstmt.executeQuery();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try {
			if (rs.next()) {
				loginFlag = true;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			DbUtil.closeResource(rs, pstmt, conn);
		}
		
		return loginFlag;
	}

}
